<?php

class Project_Image extends Project_File {
	private $width;
	private $height;
	private $text;

	public static function getByName($dir, $name, $class = null) {
		if (is_null($class)) $class = __CLASS__;
		return parent::getByName($dir, $name, $class);
	}

	public function getXml(array $attributes = array(), $xml = null, $nodeName = 'image') {
		$values = array(
			'width' => $this->getWidth(),
			'height' => $this->getHeight()
		);

		if ('' != $this->getText()) {
			$xml .= '<text><![CDATA[' . $this->getText() . ']]>';
		}

		return parent::getXml(array_merge($values, $attributes), $xml, $nodeName);
	}

	public function setPath($path) {
		parent::setPath($path);

		$size = getimagesize($this->getPath());
		list($this->width, $this->height) = $size;
	}

	public function getWidth() {
		return $this->width;
	}

	public function getHeight() {
		return $this->height;
	}

	public function setText($value) {
		$this->text = $value;
	}

	public function getText() {
		return $this->text;
	}
}
